package com.smm.web.vmc.controller.admin;

import com.smm.web.vmc.domain.Alam;
import com.smm.web.vmc.domain.Receipt;
import com.smm.web.vmc.dto.CameraDto;
import com.smm.web.vmc.dto.JsonReturn;
import com.smm.web.vmc.service.AlamService;
import com.smm.web.vmc.service.ReceiptService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Created by zhenghao on 2016/9/12.
 *
 *
 */
@Controller
@RequestMapping("/admin/alam")
public class AdminAlamController {


    @Resource
    private ReceiptService receiptService;


    @Resource
    private AlamService alamService;


    @RequestMapping("/listByRep.do")
    public ModelAndView listByRep(String repNo){

        ModelAndView mv = new ModelAndView("admin/alam/list");

        //获取仓单信息
        Receipt receipt = receiptService.getOneById(repNo);

        //获取指定仓单的所有报警记录
        Map<String,List<Alam>> groupAlamMap  = alamService.getGroupByDateForRep(repNo);

        mv.addObject("receipt",receipt);
        mv.addObject("groupAlamMap",groupAlamMap);

        return mv;

    }




    @RequestMapping("/process.do")
    @ResponseBody
    public JsonReturn process(int id,String desc){

        try{

            alamService.process(id,desc);

        }catch (Exception e){

            e.printStackTrace();

            return new JsonReturn(0,"处理失败！"+e.getMessage());
        }

        return new JsonReturn(1,"处理成功");
    }




}
